<script setup>
import { NButton } from "naive-ui"
// 避免 $attrs 透传到 popconfirm
defineOptions({ inheritAttrs: false })
const emits = defineEmits(["positive-click", "negative-click"])

defineProps({
  text: {
    type: String,
    required: true,
  },
  title: {
    type: String,
    default: '确认操作'
  },
  content: {
    type: String,
    default: '是否确认此操作？'
  },
  positiveText: {
    type: String,
    default: '确认'
  },
  negativeText: {
    type: String,
    default: '取消'
  }
})
</script>

<template>
 <div>
   <n-popconfirm
       :title="title"
       :positive-text="positiveText"
       :negative-text="negativeText"
       @positive-click="emits('positive-click')"
       @negative-click="emits('negative-click')"
   >
     <template #trigger>
       <!-- 外部传的属性都透传给 NButton -->
       <n-button v-bind="$attrs">{{ text }}</n-button>
     </template>
     {{ content }}
   </n-popconfirm>
 </div>
</template>
